/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-11-24 15:38:32
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-12-24 18:49:17
 * @FilePath: \WingsUpdater-main\inc\Service\Service.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#pragma once
#include "Result.h"
#include <thread>
#include <atomic>
#include <mutex>

// front declaration.
class IPackageResolver;

// class
class Service 
{
public:
    virtual ~Service();
    static Service *instance();
    bool run();
protected:
    Service() = default;
    Result init();
    void update(IPackageResolver *resolver);
    void deinit();
protected:
    std::mutex m_flagLock;
    bool m_updateFlag = false;
    std::thread m_tcpResolverWorker;
    std::atomic<bool> m_tcpResolverExitFlag = true;
    std::thread m_udpResolverWorker;
    std::atomic<bool> m_udpResolverExitFlag = true;
};
